package api

import (
	"github.com/gorilla/mux"
	"net/http"
	"com/ys/model"
	"com/ys/tool"
)

func initUserApi(r *mux.Router) {

	router := r.PathPrefix("/user").Subrouter()
	router.HandleFunc("/list", UserListHandler)
	router.HandleFunc("/add", UserAddHandler)
	router.HandleFunc("/login", UserLoginHandler)
}

/**
用户登录
 */
func UserLoginHandler(writer http.ResponseWriter, request *http.Request) {

	user := &model.User{}
	tool.GetJsonFromReq(request, user)
	resp := &model.Resp{Code: "1001", Msg: "账户或者密码错误"}
	if user.Username == "ys" && user.Password == "12345" {
		resp = &model.Resp{Code: "0", Msg: "success"}
	}
	tool.ConvertObject2JsonResp(writer, resp)

}

/**
用户列表
 */
func UserListHandler(w http.ResponseWriter, req *http.Request) {

}

/**
新增用户
 */
func UserAddHandler(writer http.ResponseWriter, request *http.Request) {

}
